package com.hsr.web.controller;


import com.hsr.web.dto.MenuDTO;
import com.hsr.web.dto.MenuQuery;
import com.hsr.web.dto.MessageDTO;
import com.hsr.web.dto.MessageQuery;
import com.hsr.web.entity.TMenu;
import com.hsr.web.entity.TMessage;
import com.hsr.web.service.ITMessageService;
import com.hsr.web.utils.ResultVOUtil;
import com.hsr.web.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author tb
 * @since 2022-04-11
 */
@RestController
@Api(tags = "意见相关接口")
@RequestMapping("/message")
public class TMessageController {


    @Autowired
    ITMessageService messageService;

    @PostMapping("/list")
    @ApiOperation("查询")
    public ResultVO list(@RequestBody MessageQuery query) {
        return ResultVOUtil.success(messageService.getList(query));
    }

    @PutMapping
    @ApiOperation("新增")
    public ResultVO insert(@RequestBody MessageDTO messageDTO){
        TMessage message = new TMessage();
        BeanUtils.copyProperties(messageDTO,message);
        message.setCreateTime(LocalDateTime.now());
        messageService.save(message);
        return ResultVOUtil.success();
    }


    @DeleteMapping("/{id}")
    @ApiOperation("删除")
    public ResultVO delete(@PathVariable Integer id){
        messageService.removeById(id);
        return ResultVOUtil.success();
    }

}
